﻿<div ng-controller="Supplier_EditC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">编辑仓库信息</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>仓库名称</label>
                                <input ng-model="editdata.Name" type="text" class="form-control" required >
                            </div>
                            <div class="form-group">
                                <label>
                                    区域
                                    <!--<button type="button" class="btn btn-xs btn-default" ng-click="editisture()">
                                        <i class="fa fa-plus text"></i>
                                        <span class="text">修改</span>
                                    </button>-->
                                </label>
                                <!--<div class="input-group" ng-if="istrue">
                                    <span class="input-group-addon">省</span>
                                    <select disabled="disabled" class="form-control">
                                        <option selected = "selected">editdata.District.Parent.Name</option>
                                    </select>
                                    <span class="input-group-addon">市</span>
                                    <select disabled="disabled" class="form-control">
                                        <option selected = "selected">editdata.District.Name</option>
                                    </select>
                                </div>-->
                                <div class="input-group" >
                                    <span class="input-group-addon">省</span>
                                    <select required class="form-control" ng-options="x.FillName for x in districts" ng-model="selectedDistrict1"></select>
                                    <span class="input-group-addon">市</span>
                                    <select required class="form-control" ng-options="x as x.Name for x in selectedDistrict1.Children track by x.Id" ng-model="editdata.District"></select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label>先款优惠(例如：-5)</label>
                                <input ng-model="editdata.FullPaymentDiscount" type="number" min="0" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>非标优惠(例如：-300)</label>
                                <input ng-model="editdata.NonstandardDiscount" type="number" min="0" class="form-control" required>
                            </div>

                            <!--<div class="form-group" ng-if="istrue2">
                                <label>
                                    客户经理
                                    <button type="button" class="btn btn-xs btn-default" ng-click="editisture2()">
                                        <i class="fa fa-plus text"></i>
                                        <span class="text">修改</span>
                                    </button>
                                </label>
                                <select disabled="disabled" class="form-control">
                                    <option selected = "selected">{{editdata.Manager.Name}}</option>
                                </select>
                            </div>-->
                            <div class="form-group" >
                                <label>区域经理</label>
                                <select required class="form-control" ng-options="x as x.Name for x in userdata  track by x.Id" ng-model="editdata.Manager"></select>
                            </div>
                            <!--<div class="form-group" ng-if="istrue3">
                                <label>
                                    驻厂专员
                                    <button type="button" class="btn btn-xs btn-default" ng-click="editisture3()">
                                        <i class="fa fa-plus text"></i>
                                        <span class="text">修改</span>
                                    </button>
                                </label>
                                <select disabled="disabled" class="form-control">
                                    <option selected = "selected">editdata.FieldMans.Name</option>
                                </select>
                            </div>-->
                            <div class="form-group" >
                                <label>驻厂专员</label>
                                <select required class="form-control" ng-options="x.Name for x in userdata  track by x.Id" ng-model="editdata.MainFieldMan"></select>
                            </div>
                            <div class="row text-right" style="text-align:center">
                                <button type="button" class="btn btn-success" ng-disabled="form.$invalid" ng-click="suppsub()">确认修改</button>
                                <span style="padding:0 5%"></span>
                                <button type="button" class="btn" ng-click="abolish()">取消</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
        .controller("Supplier_EditC", function ($scope, $state, $http,$stateParams) {
            $scope.selectedDistrict1 = "";
            $scope.istrue = true;
            $scope.istrue2 = true;
            $scope.istrue3 = true;
//            修改按钮
            $scope.editisture = function(){
                $scope.istrue = false;
            };
            $scope.editisture2 = function(){
                $scope.istrue2 = false;
            };
            $scope.editisture3 = function(){
                $scope.istrue3 = false;
            };
            //请求数据
            $http({
                url: "/api/Provider/" + $stateParams.id,
                method: "GET"
            })
                    .then(function (res) {
                        console.log(res.data);
                        $scope.editdata = res.data;
                    console.log($scope.editdata.District);
                })
                    .then(function (error) {
                        if (error) {
                            console.log("error");
                        }
                    });

            //获取地市
            $http({
                url:"../api/District",
                method:"GET"
            })
                    .then(function (res) {
                        $scope.districts = res.data;
                        if ($scope.editdata.District) {
                            for (var i = 0; i < $scope.districts.length; i++) {
                                if ($scope.districts[i].Id == $scope.editdata.District.Parent.Id) {
                                    $scope.selectedDistrict1 = $scope.districts[i];
                                    break;
                                }
                            }
                        }
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
            //获取人员
            $http({
                url:"../api/Employee/List?name=&page=1&rows=9999",
                method:"GET"
            })
                    .then(function (res) {
                        $scope.userdata = res.data.Data;
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
//            提交信息
            $scope.suppsub = function(){
                $http.put('../api/Provider', $scope.editdata)
                        .success(function(res){
                            console.log(res);
                            alert("修改成功");
                            $state.go('app.Supplier_Provider');
                        });
            };
            //取消更改
            $scope.abolish = function(){
                $state.go('app.Supplier_Provider');
            }

        })

</script>